package com.zhanghe.springsecurity.Service;

import com.zhanghe.springsecurity.model.User;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * UserService
 *
 * @author Clevo
 * @date 2018/3/25
 */
@Component
public class UserService implements UserDetailsService {
    @Override
    public User loadUserByUsername(String s) throws UsernameNotFoundException {
        User user = new User();
        user.setUserName(s);
        user.setPassword("123456");
        if(user.getUsername().equals("admin")){
            user.setRoles(new ArrayList<String>(){{add("ROLE_ADMIN");add("ROLE_SELLER");}});
        }else if(user.getUsername().equals("seller")){
            user.setRoles(new ArrayList<String>(){{add("ROLE_SELLER");}});
        }else{
            return null;
        }

        return user;
    }
}
